
/*
* 贷后管理首页 台账 js
*
* */
var layer;
var table;
var basePath;
var vm;
var tableColum;
// var templateCode = document.getElementById("templateCode").getAttribute("value");
window.layinit(function (htConfig) {
    var _htConfig = htConfig;
    basePath = _htConfig.coreBasePath;
    uiBasePath = _htConfig.uiBasePath;
    vm = new Vue({
        el: '#app',
        data: {

        },

        methods: {
            //重载表格
            toLoading: function () {
                if (table == null) {
                    return;
                }
                var self = this;
                self.loading = true;
                table.reload('listTable', {
                    where: {
                        paydayTimeYear: self.searchForm.paydayTimeYear,  //发薪年份

                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            },
            handleReset: function (name) { // 重置表单
                vm.searchForm.trailerStartDate = '';
                vm.searchForm.trailerEndDate = '';

                vm.searchForm.status = '';
                //var a=$("#trailerStartDate");
                //console.log(a);
                //alert(JSON.stringify(a));
                var tt = this.$refs[name];
                tt.resetFields();
                vm.toLoading();
            },
            ////  ----   单行操作界面显示  结束 -----------------
            clickExport: function () {//导出Excel表格

            },
            init: function () {
                var self = this;
                self.getSalaryTable();
                self.getTableColum(templateCode);
                //使用layerUI的表格组件
                layui.use(['layer', 'table', 'ht_ajax', 'ht_auth', 'ht_config'], function () {
                    layer = layui.layer;
                    table = layui.table;
                    //执行渲染
                    table.render({
                        elem: '#listTable' //指定原始表格元素选择器（推荐id选择器）
                        , id: 'listTable'

                        , cols: [tableColum], //设置表头
                        url: basePath + 'salarySheet/getSalaryTableData',

                        page: true,
                        done: function (res, curr, count) {
                            //数据渲染完的回调。你可以借此做一些其它的操作
                            //如果是异步请求数据方式，res即为你接口返回的信息。
                            //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                            self.loading = false;
                        }
                    });
                    table.on('edit(listTable)',function (obj) {
                        console.log("=======>>>>>>>单元格修改属性",obj);
                        self.updataSalary(obj);
                    });
                    table.on('tool(listTable)', function (obj) {
                        var selectedRowInfo = obj.data;
                        if(obj.event === 'delete'){
                            layer.confirm('真的删除么?', function(index){
                                self.deleteForm.params.push(obj.data);
                                self.deleteSalaryData();
                                layer.close(index);
                            });
                        }
                    });
                })
            },
            getTableColum:function (templateCode) {
                var self = this;
                if(templateCode == "" || templateCode == null || templateCode == undefined){
                    templateCode = "test1";
                }
                self.deleteForm.templateCode = templateCode;

                var url = basePath + "salarySheet/getTableColum?templateCode="+templateCode;
                $.ajax({
                    type: "GET",
                    url: url,
                    contentType: "application/json; charset=utf-8",
                    async: false,
                    dataType: "json",
                    success: function (result) {
                        console.log("结果：========",result);
                        if (result.returnCode == "0") {
                            console.log("动态表名==========",result.data);
                            tableColum = result.data;
                            console.log("返回参数=====",tableColum);
                        }
                    }

                });
            },
            //单元格更新
            updataSalary:function (obj) {
                var value = obj.value //得到修改后的值
                    ,data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
                var self = this;
                self.eidtForm.value=value;
                self.eidtForm.fieldName=field;
                self.eidtForm.fileId=data.file_id;
                self.eidtForm.jobCode=data.job_code;

                var url = basePath + "salarySheet/updataSalary";

                var data = JSON.stringify(self.eidtForm);
                console.log("data========>>>>>>",data);
                $.ajax({
                    type: "POST",
                    url: url,
                    contentType: "application/json; charset=utf-8",
                    async: false,
                    data:data ,
                    dataType: "json",
                    success: function (result) {
                        console.log("结果：========",result);
                        if (result.returnCode == "0") {
                            console.log("动态表名==========",result.data);
                            layer.msg("更新成功");
                            self.toLoading();
                        }else {
                            layer.msg(result.msg);
                            self.toLoading();
                        }
                    },
                    error:function (result) {
                        layer.msg("更新成功失败："+result.msg);
                    }

                });

            },
            uploadInitData:function () {
                alert(123);
            }

        },
        mounted:function(){
            // this.init();
        }
    });
});
//














